import React, { useEffect, useState } from 'react';
import { Select, Input, Table, Radio, Tag, Switch, message, Modal } from 'antd';
interface Props{
    list?:any,
    columns?:any
}
function MyForm(props:Props) {
    var [truelist, setTruelist] = useState([])
    const [selectionType, setSelectionType] = useState<'checkbox' | 'radio'>('checkbox');
    var [pagination, setPagination] = useState({ current: 1, pageSize: 10, total: 100 })
    var [loading, setLoading] = useState(false)
    // 多选
    const rowSelection = {
        onChange: (selectedRowKeys: any, selectedRows: any) => {
            console.log(`selectedRowKeys: ${selectedRowKeys}`, 'selectedRows: ', selectedRows);
            setTruelist(selectedRowKeys)
        }
    }
     // 分页发生改变后执行
     const handleChange = (pagi:any) =>{
        setPagination(pagi) //更新页码
        setLoading(true)
        // 请求新的页码对应的数据
        // getMngtable().then(res=>{
        //     setLoading(false)
        //     setPagination({
        //             ...pagi,total:res.data.length
        //         })
        // })
    }
    return (
        <div className='myform'>
            <Radio.Group
                onChange={({ target: { value } }) => {
                    setSelectionType(value);
                }}
                value={selectionType}
            >
            </Radio.Group>
            <Table
                scroll={{ x: 1500 }}
                rowSelection={{
                    type: selectionType,
                    ...rowSelection,
                }}
                dataSource={props.list}
                rowKey={(record: any) => record.id}
                pagination={pagination}
                onChange={(pagi) => { handleChange(pagi) }}
                loading={loading}
                columns={props.columns} />
        </div>
    );
}

export default MyForm;